#include<stdio.h>
#include<string.h>

int main()
{
	int n,k,i,t,num;
	int a[1010];
	while (scanf("%d%d",&n,&k)==2)
	{
		if (n==0&&k==0)
		{
			printf("End Of Input\n");
			break;
		}
		if (n<=3||n>=1000||k<=3||k>=n)
		{
			printf("Input Error\n");
			continue;
		}
		memset(a,0,sizeof(a));
		for (i=1;i<=n;i++)
			a[i]=1;
		num=0;
		t=n;
		for (i=1;;i++)
		{
			if (i==n+1)
				i=1;
			if (a[i]==1)
				num++;
			else
				continue;
			if (num%k==0)
			{
				a[i]=0;
				t--;
			}	
			if (t==1)
				break;
		}
		for (i=1;i<=n;i++)
			if (a[i])
				printf("%d\n",i);
	}
	return 0;
}
